package com.demo.Service;

import com.demo.Mapper.UserMapper;
import com.demo.Model.Cj;
import com.demo.Model.Login;
import com.demo.Model.SessionMap;
import com.demo.Model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {

    @Autowired
    UserMapper userMapper;

    public List<User> query(){
        return userMapper.query();
    }

    public void deleteById(int id){
        userMapper.deleteById(id);
    }

    public void insert(User user){
        userMapper.insert(user);
    }

    public List<User> queryById(int id){
        return userMapper.queryById(id);
    }

    public void updateById(User user){
        userMapper.updateById(user);
    }

    public List<Login> log(int xh, String password){
        return userMapper.log(xh, password);
    }

    public List<Cj> queryCj(int xh){
        return userMapper.queryCj(xh);
    }

    public boolean checkLogined(Integer xh){
        String sid = String.valueOf(xh);
        Object obiect = SessionMap.sessionMap.get(sid);
        if(obiect == null){
            return false;
        }
        return true;
    }

    public List<User> queryByPage(int start, int row){
        return userMapper.queryByPage(start, row);
    }
}
